$(function(){
    var type = GetQueryString("type");
    if(!isNaN(type)){
        $(".menus").find("li").removeClass("active");
        $(".menus").find("li").eq(parseInt(type)).addClass("active");
    }else{
        $(".menus").find("li").eq(0).addClass("active");
    }
    $(".pages").on("click","a",function(){
        var type = $(this).attr("aria-label")
        var current = $(".pages").find(".active a").text();
        if( type == "Previous"){
            //上一页
            if("1" == current){
                return;
            }else{
                ChangeParam("page",current - 1);
            }
        }else if(type == "Next"){
            //下一页
            if(current == $(".pages").attr("data-total")){
                return;
            }else { 
                ChangeParam("page",current);
            }
        }else{
            ChangeParam("page",type);
        }
    })
})
/**
 * 获取url参数
 * @param {*} name 
 */
function GetQueryString(name){
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
/**
 * 修改url参数
 * @param {*} name 
 * @param {*} value 
 */
function ChangeParam(name,value) {
    var url = window.location.href ;
    var newUrl="";
    var reg = new RegExp("(^|)"+ name +"=([^&]*)(|$)");
    var tmp = name + "=" + value;
    if(url.match(reg) != null) {
        newUrl= url.replace(eval(reg),tmp);
    }
    else {
        if(url.match("[\?]")) {
            newUrl = url + "&" + tmp;
        }
    else {
            newUrl = url + "?" + tmp;
        }
    }
    location.href = newUrl;
}
/**
 * 判断是否登录
 */
function hasLogin (){
    if(getCookie("uuid")){
        return true;
    }
    return false;
}